package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.common.dto.CategoryDto;
import com.itheima.reggie.common.dto.DishListDto;
import com.itheima.reggie.common.dto.DishUpdateDto;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.service.DishService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liu
 * @date: 2022/02/27
 * @time: 16:50
 */
@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    DishService dishService;

    @PostMapping
    public R<String> dish(@RequestBody CategoryDto categoryDto) {
        return dishService.dish(categoryDto);
    }

    @GetMapping("/page")
    public R<Page<DishListDto>> findDishPage(Long page, Long pageSize, String name) {
        return dishService.findDishPage(page, pageSize, name);
    }

    @GetMapping("{id}")
    public R<DishUpdateDto> findDishById(@PathVariable Long id) {
        return dishService.findDishById(id);
    }

    @PutMapping
    public R<String> updateDish(@RequestBody DishUpdateDto dishUpdateDto) {
        return dishService.updateDish(dishUpdateDto);
    }

    @GetMapping("/list")
    public R<List<DishUpdateDto>> findDishByCategoryId(Long categoryId, Integer status) {
        return dishService.findDishByCategoryId(categoryId, status);
    }

    /**
     * 菜品批量删除
     *
     * @param ids
     * @return String
     */
    @DeleteMapping
    public R<String> deleteById(@RequestParam List<Long> ids) {
        return dishService.deleteById(ids);
    }

    /**
     * 菜品批量停售
     *
     * @param ids
     * @return String
     */
    @PostMapping("/status/0")
    public R<String> stopSell(@RequestParam List<Long> ids) {
        return dishService.stopSell(ids);
    }

    @PostMapping("/status/1")
    public R<String> startSell(@RequestParam List<Long> ids) {
        return dishService.startSell(ids);
    }
}
